/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabelamodelcolumnmodel.fornecedor;

import eloma.classe.Fornecedor;
import java.util.List;
import javax.swing.JFormattedTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Icaro
 */
public class FornecedorTableModel extends AbstractTableModel {

    MaskFormatter tel;
    JFormattedTextField jftf;
    private List<Fornecedor> listFornecedor;
    private boolean ordenarPorNome = true;

    public FornecedorTableModel(List<Fornecedor> listFornecedor) {
        this.listFornecedor = listFornecedor;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Fornecedor fornecedor = listFornecedor.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return fornecedor.getNome();
            case 1:
                try {
                    tel = new MaskFormatter("(##)####-####");
                    tel.setPlaceholderCharacter('_');

                    jftf = new JFormattedTextField(tel);
                    jftf.setText(String.valueOf(fornecedor.getTelefone()));

                    return jftf.getText();

                } catch (Exception e) {
                }
        }

        return null;
    }

    @Override
    public int getRowCount() {
        return listFornecedor.size();
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    public Fornecedor getValoresFirnecedor(int rowIndex) {
        return listFornecedor.get(rowIndex);
    }

    public boolean isOrdenarPorNome() {
        return ordenarPorNome;
    }

    public void setOrdenarPorNome(boolean ordenarPorNome) {
        this.ordenarPorNome = ordenarPorNome;
    }
}
